home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
games
/
2a
/
applicat.ion
/
slider.doc
< prev
next >
Wrap
Text File
|
1985-05-29
|
7KB
|
199 lines
Dialog box slider subroutines
by Tom Hudson
Here's a set of subroutines that will help GEM developers put
sliders similar to those on GEM windows in their dialog
boxes. Up to ten sliders per window are supported (more can
be added by changing four arrays), both horizontal and
vertical, in any combination. They can be monitored at the
same time as other items in the dialog, and each slider can
be independently scaled. The slider subroutine returns true
step values (not 0-1000 as in GEM sliders), so no additional
processing is necessary.
There are four other files in the DL area that you will want
to download. These are:
SLIDER.C -- C source for a slider test program
SLIDES.H -- Resource index names for the test program
SLIDES.DEF -- Resource definition file
SLIDES.RSC -- Slider test dialog resource for test program
Setting up the dialog.
Using the Resource Construction Set, load the SLIDES.RSC
resource. This file contains one dialog box, which
demonstrates how to set up the sliders in your own dialogs.
To build the necessary items for a slider, you will need two
buttons and two boxes. One of the boxes will be the slider
"track", which limits the movement of the slider itself.
Make the slider box as big as required. To maintain user
recognition, it is suggested that a track be defined with a
dot pattern, like the GEM window sliders. NAME the track
appropriately (i.e. TRACK1). The track can be any width, and
can run horizontally or vertically.
Next, place another box ON the track box. You will be warned
that this movement changes the object order. This is OK.
Size this new box so that it fits inside the track -- this is
the movable slider. NAME it appropriately (i.e. SLIDER1).
Finally, set the slider object so that it is a TOUCHEXIT item
(no other options selected).
Now define two buttons with arrow characters in the two
directions appropriate for the slider, labeling them
accordingly (i.e. UP1/DOWN1 or LEFT1/RIGHT1). Make these
items TOUCHEXIT items and place them at either end of the
slider track.
Build your dialog box with as many sliders as you like, just
remember to label all four slider elements and make the
slider and the direction buttons TOUCHEXIT items.
The program.
The SLIDER.C program shows how to handle a dialog box with
four independent sliders in it (two horizontal, two
vertical). The code isn't fancy or particularly optimized,
but then I wrote it at 2 A.M. It does things the quickest
way I could think of, and you may want to clean it up.
Whatever it looks like, it works.
To use the slider routines in your programs, you will need
the four slider functions (hreset, vreset, do_hslider &
do_vslider) and their control variables (slidstep[],
slidacc[], slidpos[] and slidmax[]).
The actual slider usage starts by drawing the dialog box with
the objc_draw call. Next, you must initialize all the
sliders you use. This is done with the hreset and vreset
calls.
To initialize a slider, you must provide the slider number
(0-9), the address of the dialog box form, the index of the
slider's track object, the index of the slider object itself,
the maximum slider setting, and the initial slider setting.
For a slider with 35 possible positions, the maximum slider
setting would be set to 34 (because the range is 0-34). To
make the slider initially at the left of a horizontal slider
or the top of a vertical slider, set the initial slider
setting to 0. Setting this to 34 will place the slider at
the right of a horizontal slider or the bottom of a vertical
slider. You can set the initial position to anything between
0 and the maximum; the slider subroutine automatically
determines the proper setting for anything in-between.
For example, the first slider in the example program
(SLIDER0) has 11 possible positions and is initially set to
position 1.
After all sliders are initialized, you call form_do to
monitor the user's interaction with the dialog.
Because the slider and its direction control buttons are
TOUCHEXIT items, as soon as the mouse is clicked on them the
form_do function will return with their index numbers. You
then check the index, seeing if it's a slider or button for a
particular slider and call the do_hslider or do_vslider
function, passing the slider's index number to the function,
along with the dialog's address, the track index, slider
index, control button indexes and the index number of the
item that caused the exit from the form_do.
The do_hslider and do_vslider functions will process the
slider and return when finished. You should then re-enter
the form_do. Repeat this process until the form_do returns
with one of the exit buttons (i.e. OK or CANCEL).
If the form was exited with the OK button, you must take the
slider values and place them into your work areas for
processing. The settings of the sliders can be found in the
slidpos[] array. These settings will be from 0 to the
maximum value you selected in the hreset or vreset call.
The demo program will repeat the slider test dialog each time
it is exited and you press a key other than the RETURN key.
This allows you to see how the OK and Cancel buttons affect
the sliders. To quit the program, exit the dialog and press
RETURN.
This set of functions was designed to work with just about
any application or dialog and should work fine in your
programs. Just examine the example program and experiment.
Modification of these functions should be relatively easy --
have fun. If you have any trouble, drop me a note on the
16-bit SIG.
-Tom Hudson 70775,424